home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbpcopy / jmscreen.bas < prev    next >
BASIC Source File  |  1998-10-03  |  7KB  |  269 lines

  1. Attribute VB_Name = "JMScreenSubs"
  2. Option Explicit
  3. '
  4. '  Scructure Definitions
  5.     Type RECT
  6.         Left As Long
  7.         Top As Long
  8.         Right As Long
  9.         Bottom As Long
  10.     End Type
  11.     Type APPBARDATA
  12.         cbSize As Long
  13.         hWnd As Long
  14.         uCallbackMessage As Long
  15.         uEdge As Long
  16.         rc As RECT
  17.         lParam As Long
  18.     End Type
  19. '
  20. '  Definitions
  21.     Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As APPBARDATA) As Long
  22.     Global Const ABS_ALWAYSONTOP = &H2
  23.     Global Const ABS_AUTOHIDE = &H1
  24.     Global Const ABM_GETSTATE = &H4
  25.     Global Const ABM_GETTASKBARPOS = &H5
  26.  
  27. Public Function JMTaskbarExists() As Integer
  28.     Dim wrkBar As APPBARDATA
  29.     On Error Resume Next
  30. '
  31. '  Set Size of Structure
  32.     wrkBar.cbSize = 36
  33. '
  34. '  Get Status of Taskbar
  35.     Select Case SHAppBarMessage(ABM_GETSTATE, wrkBar)
  36.     Case ABS_ALWAYSONTOP, ABS_AUTOHIDE
  37. '
  38. '  Taskbar exists
  39.         JMTaskbarExists = True
  40.         Exit Function
  41.     End Select
  42. '
  43. '  Taskbar does not
  44.     JMTaskbarExists = False
  45. End Function
  46.  
  47.  
  48. Public Function JMScreenHeight() As Long
  49.     Dim wrkBar As APPBARDATA
  50.     Dim wrkHeight As Long
  51.     Dim wrkTop As Long
  52.     Dim wrkBottom As Long
  53.     On Error GoTo JMScreenHeightError
  54. '
  55. '  Set Default Height
  56.     JMScreenHeight = Screen.Height
  57. '   JMScreenHeight = 480 * Screen.TwipsPerPixelY
  58. '   Exit Function
  59. '
  60. '  Test for a Taskbar
  61.     If (JMTaskbarExists() = False) Then Exit Function
  62. '
  63. '  Set Size of Structure
  64.     wrkBar.cbSize = 36
  65. '
  66. '  Get Size and Position of Taskbar
  67.     wrkHeight = Screen.Height / Screen.TwipsPerPixelY
  68.     If (SHAppBarMessage(ABM_GETTASKBARPOS, wrkBar) = False) Then Exit Function
  69. '
  70. '  Extract Top and Bottom
  71.     wrkTop = wrkBar.rc.Top
  72.     wrkBottom = wrkBar.rc.Bottom
  73. '
  74. '  Set if Bar is Vertical
  75.     If (wrkTop <= 0 And wrkBottom >= wrkHeight) Then
  76.         wrkHeight = Screen.Height
  77. '
  78. '  Set if Bar is at Top
  79.     ElseIf (wrkTop < 0) Then
  80.         wrkHeight = (wrkHeight - wrkBottom) * Screen.TwipsPerPixelY
  81. '
  82. '  Set if Bar is at Bottom
  83.     ElseIf (wrkBottom >= wrkHeight) Then
  84.         wrkHeight = wrkTop * Screen.TwipsPerPixelY
  85. '
  86. '  Set if Anywhere Else (Shouldn't be!)
  87.     Else
  88.         wrkHeight = Screen.Height
  89.     End If
  90. '
  91. '  Set Height
  92.     JMScreenHeight = wrkHeight
  93.     Exit Function
  94. '
  95. '  Error
  96. JMScreenHeightError:
  97.     JMScreenHeight = Screen.Height
  98.     Exit Function
  99. End Function
  100. Public Function JMScreenWidth() As Long
  101.     Dim wrkBar As APPBARDATA
  102.     Dim wrkWidth As Long
  103.     Dim wrkLeft As Long
  104.     Dim wrkRight As Long
  105.     On Error GoTo JMScreenWidthError
  106. '
  107. '  Set Default Width
  108.     JMScreenWidth = Screen.Width
  109. '   JMScreenWidth = 640 * Screen.TwipsPerPixelX
  110. '   Exit Function
  111. '
  112. '  Test for a Taskbar
  113.     If (JMTaskbarExists() = False) Then Exit Function
  114. '
  115. '  Set Size of Structure
  116.     wrkBar.cbSize = 36
  117. '
  118. '  Get Size and Position of Taskbar
  119.     wrkWidth = Screen.Width / Screen.TwipsPerPixelX
  120.     If (SHAppBarMessage(ABM_GETTASKBARPOS, wrkBar) = False) Then Exit Function
  121. '
  122. '  Extract Left and Right
  123.     wrkLeft = wrkBar.rc.Left
  124.     wrkRight = wrkBar.rc.Right
  125. '
  126. '  Set if Bar is Horizontal
  127.     If (wrkLeft <= 0 And wrkRight >= wrkWidth) Then
  128.         wrkWidth = Screen.Width
  129. '
  130. '  Set if Bar is at Left
  131.     ElseIf (wrkLeft < 0) Then
  132.         wrkWidth = (wrkWidth - wrkRight) * Screen.TwipsPerPixelX
  133. '
  134. '  Set if Bar is at Right
  135.     ElseIf (wrkRight >= wrkWidth) Then
  136.         wrkWidth = wrkLeft * Screen.TwipsPerPixelY
  137. '
  138. '  Set if Anywhere Else (Shouldn't be!)
  139.     Else
  140.         wrkWidth = Screen.Width
  141.     End If
  142. '
  143. '  Set Width
  144.     JMScreenWidth = wrkWidth
  145.     Exit Function
  146. '
  147. '  Error
  148. JMScreenWidthError:
  149.     JMScreenWidth = Screen.Width
  150.     Exit Function
  151. End Function
  152.  
  153. Public Function JMScreenTop() As Long
  154.     Dim wrkBar As APPBARDATA
  155.     Dim wrkScreenTop As Long
  156.     Dim wrkHeight As Long
  157.     Dim wrkTop As Long
  158.     Dim wrkBottom As Long
  159.     On Error GoTo JMScreenTopError
  160. '
  161. '  Set Default Top
  162.     JMScreenTop = 0
  163. '
  164. '  Test for a Taskbar
  165.     If (JMTaskbarExists() = False) Then Exit Function
  166. '
  167. '  Set Size of Structure
  168.     wrkBar.cbSize = 36
  169. '
  170. '  Get Size and Position of Taskbar
  171.     If (SHAppBarMessage(ABM_GETTASKBARPOS, wrkBar) = False) Then Exit Function
  172. '
  173. '  Extract Top and Bottom
  174.     wrkTop = wrkBar.rc.Top
  175.     wrkBottom = wrkBar.rc.Bottom
  176. '
  177. '  Set Screen Height
  178.     wrkHeight = Screen.Height / Screen.TwipsPerPixelY
  179. '
  180. '  Set if Bar is at Top
  181.     If (wrkTop < 0 And wrkBottom < wrkHeight) Then
  182.         wrkScreenTop = wrkBottom * Screen.TwipsPerPixelY
  183. '
  184. '  Set if Anywhere Else
  185.     Else
  186.         wrkScreenTop = 0
  187.     End If
  188. '
  189. '  Set Top
  190.     JMScreenTop = wrkScreenTop
  191.     Exit Function
  192. '
  193. '  Error
  194. JMScreenTopError:
  195.     JMScreenTop = 0
  196.     Exit Function
  197. End Function
  198.  
  199. Public Function JMScreenLeft() As Long
  200.     Dim wrkBar As APPBARDATA
  201.     Dim wrkScreenLeft As Long
  202.     Dim wrkWidth As Long
  203.     Dim wrkLeft As Long
  204.     Dim wrkRight As Long
  205.     On Error GoTo JMScreenLeftError
  206. '
  207. '  Set Default Top
  208.     JMScreenLeft = 0
  209. '
  210. '  Test for a Taskbar
  211.     If (JMTaskbarExists() = False) Then Exit Function
  212. '
  213. '  Set Size of Structure
  214.     wrkBar.cbSize = 36
  215. '
  216. '  Get Size and Position of Taskbar
  217.     If (SHAppBarMessage(ABM_GETTASKBARPOS, wrkBar) = False) Then Exit Function
  218. '
  219. '  Extract Left and Right
  220.     wrkLeft = wrkBar.rc.Left
  221.     wrkRight = wrkBar.rc.Right
  222. '
  223. '  Set Screen Height
  224.     wrkWidth = Screen.Width / Screen.TwipsPerPixelX
  225. '
  226. '  Set if Bar is at Left
  227.     If (wrkLeft < 0 And wrkRight < wrkWidth) Then
  228.         wrkScreenLeft = wrkRight * Screen.TwipsPerPixelX
  229. '
  230. '  Set if Anywhere Else
  231.     Else
  232.         wrkScreenLeft = 0
  233.     End If
  234. '
  235. '  Set Left
  236.     JMScreenLeft = wrkScreenLeft
  237.     Exit Function
  238. '
  239. '  Error
  240. JMScreenLeftError:
  241.     JMScreenLeft = 0
  242.     Exit Function
  243. End Function
  244.  
  245. Public Sub SetFormPosition(frmSetup As Form, argTop As Long, argLeft As Long)
  246.     On Error Resume Next
  247. '
  248. '  Position Form
  249.     frmSetup.Left = argLeft
  250.     frmSetup.Top = argTop
  251. '
  252. '  Check not too far right
  253.     If ((frmSetup.Left + frmSetup.Width) > (JMScreenLeft() + JMScreenWidth())) Then
  254.         frmSetup.Left = JMScreenLeft() + JMScreenWidth() - frmSetup.Width
  255.     End If
  256. '
  257. '  Check not too far down
  258.     If ((frmSetup.Top + frmSetup.Height) > (JMScreenTop() + JMScreenHeight())) Then
  259.         frmSetup.Top = JMScreenTop() + JMScreenHeight() - frmSetup.Height
  260.     End If
  261. '
  262. '  Check not too far left
  263.     If (frmSetup.Left < JMScreenLeft()) Then frmSetup.Left = JMScreenLeft()
  264. '
  265. '  Check not too far up
  266.     If (frmSetup.Top < JMScreenTop()) Then frmSetup.Top = JMScreenTop()
  267. End Sub
  268.  
  269.